//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.niiwoo.civet.trade.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

public class SysStringUtils {
    private static final String SIGN_WHITE_SPACE = " ";
    public static Random rd = new Random();

    public SysStringUtils() {
    }

    public static boolean contain(String str, Collection<String> collection) {
        return collection.contains(str);
    }

    public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
        double radLat1 = lat1 * 3.141592653589793D / 180.0D;
        double radLat2 = lat2 * 3.141592653589793D / 180.0D;
        double a = radLat1 - radLat2;
        double b = lon1 * 3.141592653589793D / 180.0D - lon2 * 3.141592653589793D / 180.0D;
        double s = 2.0D * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2.0D), 2.0D) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2.0D), 2.0D)));
        s *= 6378137.0D;
        s = (double)(Math.round(s * 10000.0D) / 10000L);
        double d = 1.2756274E7D * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - lat2) * 3.141592653589793D / 180.0D / 2.0D), 2.0D) + Math.cos(lat1 * 3.141592653589793D / 180.0D) * Math.cos(lat2 * 3.141592653589793D / 180.0D) * Math.pow(Math.sin((lon1 - lon2) * 3.141592653589793D / 180.0D / 2.0D), 2.0D)));
        return s;
    }

    public static double getDistance(String lat1Str, String lon1Str, String lat2Str, String lon2Str) {
        double lat1 = NumberUtils.toDouble(lat1Str, 0.0D);
        double lon1 = NumberUtils.toDouble(lon1Str, 0.0D);
        double lat2 = NumberUtils.toDouble(lat2Str, 0.0D);
        double lon2 = NumberUtils.toDouble(lon2Str, 0.0D);
        double radLat1 = lat1 * 3.141592653589793D / 180.0D;
        double radLat2 = lat2 * 3.141592653589793D / 180.0D;
        double a = radLat1 - radLat2;
        double b = lon1 * 3.141592653589793D / 180.0D - lon2 * 3.141592653589793D / 180.0D;
        double s = 2.0D * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2.0D), 2.0D) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2.0D), 2.0D)));
        s *= 6378137.0D;
        s = (double)(Math.round(s * 10000.0D) / 10000L);
        double d = 1.2756274E7D * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - lat2) * 3.141592653589793D / 180.0D / 2.0D), 2.0D) + Math.cos(lat1 * 3.141592653589793D / 180.0D) * Math.cos(lat2 * 3.141592653589793D / 180.0D) * Math.pow(Math.sin((lon1 - lon2) * 3.141592653589793D / 180.0D / 2.0D), 2.0D)));
        return s;
    }

    public static double min(double... d) {
        double result = 1.7976931348623157E308D;
        double[] var3 = d;
        int var4 = d.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            double dd = var3[var5];
            if (result > dd) {
                result = dd;
            }
        }

        return result;
    }

    public static void copy(Collection c1, Collection c2, int begin, int end) {
        if (!c2.isEmpty()) {
            Iterator it = c2.iterator();

            for(int count = 0; it.hasNext(); ++count) {
                Object o = it.next();
                if (count >= begin && count <= end) {
                    c1.add(o);
                }
            }

        }
    }

    public static void copy(Collection c1, Collection c2) {
        copy(c1, c2, 0, c2.size());
    }

    public static String getMD5(String plainText) {
        if (plainText != null && !"".equals(plainText)) {
            Object var1 = null;

            byte[] secretBytes;
            try {
                secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());
            } catch (NoSuchAlgorithmException var4) {
                throw new RuntimeException("没有md5这个算法！");
            }

            String md5code = (new BigInteger(1, secretBytes)).toString(16);

            for(int i = 0; i < 32 - md5code.length(); ++i) {
                md5code = "0" + md5code;
            }

            return md5code;
        } else {
            throw new RuntimeException("加密对象为空");
        }
    }

    public static String getMsgCode() {
        return 100000 + rd.nextInt(899999) + "";
    }

    public static boolean isPhoneNum(String str) {
        return StringUtils.isEmpty(str) ? false : str.matches("^((\\+86)|(86))?[1]\\d{10}$");
    }

    public static boolean isPhoneNumLike(String str) {
        return StringUtils.isEmpty(str) ? false : str.matches("^((\\+86)|(86))?[1]\\d{5,10}$");
    }

    public static boolean isEmail(String str) {
        return StringUtils.isEmpty(str) ? false : str.matches("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
    }

    private static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    public static boolean isDate(String strDate) {
        Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
        Matcher m = pattern.matcher(strDate);
        return m.matches();
    }

    public static String toJavaVarriableName(String name) {
        if (name != null && name.length() != 0) {
            char[] chars = name.toCharArray();
            int pos = -1;

            for(int i = 0; i < chars.length; ++i) {
                char c = chars[i];
                if (c == '_') {
                    pos = i;
                } else if (c >= 'a' && c <= 'z' && pos != -1 && pos == i - 1) {
                    chars[i] = (char)(c - 32);
                }
            }

            return (new String(chars)).replaceAll("_", "");
        } else {
            return null;
        }
    }

    public static String toUnderlineVarribleName(String name) {
        if (name != null && name.length() != 0) {
            char[] chars = name.toCharArray();
            StringBuffer sb = new StringBuffer();

            for(int i = 0; i < chars.length; ++i) {
                char c = chars[i];
                if (i > 0 && c >= 'A' && c <= 'Z') {
                    sb.append('_');
                    sb.append((char)(c + 32));
                } else {
                    sb.append(c);
                }
            }

            return sb.toString();
        } else {
            return null;
        }
    }

    public static String encryptionRealName(String realName, int start) {
        if (StringUtils.isEmpty(realName)) {
            return "";
        } else {
            int length = realName.length();
            String newString = "";

            for(int i = 0; i < length - start; ++i) {
                newString = newString + "*";
            }

            return realName.substring(0, start) + newString;
        }
    }

    public static String getInvitationCodeByMobileNo(String mobileNo) {
        if (!StringUtils.isEmpty(mobileNo) && isPhoneNum(mobileNo)) {
            String binaryChar = Long.toBinaryString(Long.valueOf(mobileNo.substring(1)).longValue());
            char[] arrays = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
            StringBuffer tempZero = new StringBuffer("");

            for(int i = 0; i < 35 - binaryChar.length(); ++i) {
                tempZero = tempZero.append("0");
            }

            binaryChar = tempZero.toString().concat(binaryChar);
            StringBuffer result = new StringBuffer();

            for(int i = 0; i < 7; ++i) {
                result = result.append(arrays[Integer.valueOf(binaryChar.substring(i * 5, i * 5 + 5), 2).intValue()]);
            }

            return result.toString();
        } else {
            return "";
        }
    }

    public static String stringFilter(String str) throws PatternSyntaxException {
        if (!StringUtils.isEmpty(str) && !StringUtils.isEmpty(str.trim())) {
            String strAfterTrim = str.trim();
            String regEx = "^[A-Za-z\\s+\\d\\u4E00-\\u9FA5\\p{P}‘’“”]+$";
            Pattern p = Pattern.compile(regEx);
            StringBuilder sb = new StringBuilder();

            for(int i = 0; i < strAfterTrim.length(); ++i) {
                char c = strAfterTrim.charAt(i);
                if (Pattern.matches(regEx, String.valueOf(c))) {
                    sb.append(c);
                }
            }

            return sb.toString();
        } else {
            return str;
        }
    }

    public static Integer getInteger(Object obj, int def) {
        String str = obj == null ? "" : obj.toString();
        Integer i = null;
        if (str.trim().length() == 0) {
            i = new Integer(def);
        } else {
            try {
                i = Integer.valueOf(str);
            } catch (Exception var5) {
                ;
            }
        }

        return i == null ? new Integer(def) : i;
    }

    public static boolean isEmpty(Object obj) {
        return null == obj || "".equals(obj) || "null".equals(obj);
    }

    public static String toString(Object obj, String defaultValue) {
        return isEmpty(obj) ? defaultValue : obj.toString();
    }

    public static String toString(Object obj) {
        return isEmpty(obj) ? "" : obj.toString();
    }

    public static boolean isStartWithWhiteSpace(String paramStr) {
        return StringUtils.isNotEmpty(paramStr) ? StringUtils.startsWith(paramStr, " ") : false;
    }

    public static boolean isWithinLength(String paramStr, int length) {
        if (StringUtils.isNotBlank(paramStr)) {
            return paramStr.length() <= length;
        } else {
            return false;
        }
    }

    public static boolean isWithinLengthOfDistinguishChinese(String paramStr, int minLength, int maxLength) {
        if (!StringUtils.isNotBlank(paramStr)) {
            return false;
        } else {
            return minLength <= length(paramStr) && length(paramStr) <= maxLength;
        }
    }

    public static int length(String value) {
        int valueLength = 0;
        String chinese = "[Α-￥]";

        for(int i = 0; i < value.length(); ++i) {
            String temp = value.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 2;
            } else {
                ++valueLength;
            }
        }

        return valueLength;
    }

    public static void main(String[] args) {
        System.out.println("distance: " + getDistance(22.543099D, 114.057868D, 22.5602108834784D, 113.9570786552398D));
    }
}
